package com.example.wechat.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.wechat.R;

public class PaymentActivity extends AppCompatActivity {
    private TextView amountText;
    private TextView balanceAmount;
    private RadioButton balanceRadio;
    private RadioButton cardRadio;
    private Button payButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payment);

        // 设置工具栏
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowTitleEnabled(true);
        }

        // 初始化视图
        initViews();
        // 设置监听器
        setupListeners();
        // 加载数据
        loadData();
    }

    private void initViews() {
        amountText = findViewById(R.id.amount_text);
        balanceAmount = findViewById(R.id.balance_amount);
        balanceRadio = findViewById(R.id.balance_radio);
        cardRadio = findViewById(R.id.card_radio);
        payButton = findViewById(R.id.pay_button);
    }

    private void setupListeners() {
        // 支付方式选择
        findViewById(R.id.balance_payment).setOnClickListener(v -> {
            balanceRadio.setChecked(true);
            cardRadio.setChecked(false);
        });

        findViewById(R.id.card_payment).setOnClickListener(v -> {
            balanceRadio.setChecked(false);
            cardRadio.setChecked(true);
        });

        // 支付按钮点击
        payButton.setOnClickListener(v -> {
            if (balanceRadio.isChecked()) {
                // 使用零钱支付
                Toast.makeText(this, "正在使用零钱支付...", Toast.LENGTH_SHORT).show();
            } else {
                // 使用银行卡支付
                Toast.makeText(this, "正在使用银行卡支付...", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void loadData() {
        // 模拟数据
        amountText.setText("¥ 99.00");
        balanceAmount.setText("¥ 1,234.56");
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
} 